package com.example.demowebsocket.redis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author lsc
 * <p>订阅者1号 </p>
 */
@Component
public class RedisPusUtils {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * @param channal 通道名称
     * @param obj     消息
     */
    public void publish(String channal, User obj) {
        String s = JSON.toJSONString(obj); // 尽量转成字符串传递
        redisTemplate.convertAndSend(channal, s);
    }
}
